﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace STMS.WSTMSystem.UControls
{
    public partial class UCForm : Form
    {
        public UCForm()
        {
            InitializeComponent();
        }
        private const int WM_ERASEBKGND = 0x0014;
        private const int WM_PAINT = 0xF;
        private Color borderColor = Color.Red;
        [DefaultValue(typeof(Color), "Red"), Description("Form边框颜色")]
        public Color BorderColor
        {
            get { return borderColor; }
            set
            {
                borderColor = value;
            }
        }

        [DefaultValue(typeof(int), "5"), Description("圆角弧度大小")]
        private int radius = 5;
        public int Radius
        {
            get { return radius; }
            set
            {
                radius = value;
            }
        }

        [DefaultValue(typeof(int), "5"), Description("边框粗细")]
        private int borderWidth = 5;
        public int BorderWidth
        {
            get { return borderWidth; }
            set
            {
                borderWidth = value;
            }
        }

        protected override void WndProc(ref Message m)
        {
            try
            {
                base.WndProc(ref m);
                if (m.Msg == WM_PAINT)
                {
                    if (this.Radius > 0)
                    {
                        using (Graphics g = Graphics.FromHwnd(this.Handle))
                        {
                            g.SmoothingMode = SmoothingMode.AntiAlias;
                            Rectangle r = new Rectangle();
                            r.Width = this.Width;
                            r.Height = this.Height;
                            DrawBorder(g, r, this.Radius);

                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void DrawBorder(Graphics g, Rectangle rect, int radius)
        {
            rect.Width -= 1;
            rect.Height -= 1;

            GraphicsPath path = new GraphicsPath();
            path = PaintCommon.GetRoundRectangle(rect, radius);
            using (Pen pen = new Pen(this.BorderColor, BorderWidth))
            {
                g.DrawPath(pen, path);
            }
            Rectangle rect1 = new Rectangle(rect.X + BorderWidth, rect.Y + BorderWidth, rect.Width -BorderWidth, rect.Height - BorderWidth);

        
        }
    }
}
